package qlsl.androiddesign.view.subview.activityview;

import com.alipay.android.phone.mrpc.core.ac;
import com.qlsl.androiddesign.kuaiwa.R;

import android.content.DialogInterface;
import android.view.View;
import android.widget.BaseAdapter;
import qlsl.androiddesign.activity.subactivity.MemberProductActivity;
import qlsl.androiddesign.activity.subactivity.ShoppingDetailActivity;
import qlsl.androiddesign.activity.subactivity.ShoppingReleaseActivity;
import qlsl.androiddesign.adapter.subadapter.MemberProductAdapter;
import qlsl.androiddesign.entity.commonentity.FragmentArgs;
import qlsl.androiddesign.entity.otherentity.ShoppingDetail;
import qlsl.androiddesign.http.service.subservice.ShoppingListService;
import qlsl.androiddesign.util.commonutil.DialogUtil;
import qlsl.androiddesign.util.runfeng.ToActivityUtil;
import qlsl.androiddesign.view.subview.activityview.peoplecenterbase.PeopleCenterBaseView;

/**
 * 我的商品<br/>
 * 需要传入的键：<br/>
 * 传入的值类型： <br/>
 * 传入的值含义：<br/>
 * 是否必传 ：
 */
public class MemberProductView extends
		PeopleCenterBaseView<ShoppingDetail, MemberProductActivity> {

	private int position;

	public MemberProductView(MemberProductActivity activity) {
		super(activity);
	}

	protected void initView(View view) {
		super.initView(view);
		setTitle("我的商品");
	}

	protected void initData() {
		super.initData();
		ShoppingListService.queryShoopingList(this, activity);
	}

	protected void initListener() {
		super.initListener();
	}

	public <A> void showData(A... t) {
		super.showData(t);
		if (t[0] instanceof String) {
			ShoppingListService.queryShoopingList(this, activity);
		}
	}

	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.list_item:
			doClickListItem(view);
			break;
		case R.id.tv_under:
			doClickUnderView(view);
			break;
		}
	}

	protected void doClickListItem(View view) {

		int pos = refreshView.getRefreshableView().getPositionForView(view);
		ShoppingDetail item = (ShoppingDetail) refreshView.getAdapter()
				.getItem(pos);
		FragmentArgs args = new FragmentArgs();
		args.add("data", item);

		showToast("编辑商品正在开发中");
		return;
		// ToActivityUtil.toNextActivity(activity,
		// ShoppingReleaseActivity.class,
		// "detail", args);
		// startActivity(item, ShoppingReleaseActivity.class);

		// startActivity(item, ShoppingDetailActivity.class);
	}

	private void doClickUnderView(View view) {
		position = refreshView.getRefreshableView().getPositionForView(view);
		ShoppingDetail item = (ShoppingDetail) refreshView.getAdapter()
				.getItem(position);
		String name = null;
		if (item.getState().equals("-1")) {
			name = "确定上架该商品？";
		} else {
			name = "确定下架该商品？";
		}
		DialogUtil.showDialog(this, null, name);
	}

	public BaseAdapter getAdapter() {
		return new MemberProductAdapter(activity, list);
	}

	public void onClick(DialogInterface dialog, int which) {
		if (which == -1) {
			ShoppingDetail item = (ShoppingDetail) refreshView.getAdapter()
					.getItem(position);
			ShoppingListService.deleteGood(item.getGoodsid(), this, activity);
		}
	}

}
